﻿@model dsacbasic.Models.PagingInfo
@{
    if (Model != null && Model.TotalPages > 1)
    {
    <div class="mypager">
        <a href="@Html.Raw(Url.Action("List", new { keyword = ViewData["Keyword"], cate = ViewData["CurrentCate"], page = 1 }))">
            <img src="~/Content/img/btn_first.png" /></a>
        <a href="@Html.Raw(Url.Action("List", new { keyword = ViewData["Keyword"], cate = ViewData["CurrentCate"], page = Model.CurrentPage > 1 ? Model.CurrentPage - 1 : 1 }))">
            <img src="~/Content/img/btn_prev.png" /></a>
        @{
        //点击第10页，开始往后翻5页

        int startPage = 1;
        if (Model.CurrentPage > 5 && Model.CurrentPage % 5 == 0)
        {
            int aaa = Model.CurrentPage / 5 - 1;
            startPage = aaa * 5;
        }
        else
        {
            startPage = Model.CurrentPage / 5 * 5;
            if (Model.TotalPages - startPage < 10)
            {
                startPage = startPage - 5;
            }
            startPage = startPage <= 0 ? 1 : startPage;
            
        }
        int endPage = Model.CurrentPage < 10 ? 10 : 11;
        
        for (int i = startPage, numberPage = 1; i <= Model.TotalPages && numberPage <= endPage; i++, numberPage++)
        {
            if (i == Model.CurrentPage)
            {
            <a class="number selected" href="@Html.Raw(Url.Action("List", new { keyword = ViewData["Keyword"], cate = ViewData["CurrentCate"], page = @i }))">@i</a>
            }
            else
            {
            <a class="number" href="@Html.Raw(@Url.Action("List", new { keyword = ViewData["Keyword"], cate = ViewData["CurrentCate"], page = @i }))">@i</a>
            }

            if (i < Model.TotalPages)
            {
            @Html.Raw("|");
            }
        }
        }
        <a href="@Html.Raw(Url.Action("List", new { keyword = ViewData["Keyword"], cate = ViewData["CurrentCate"], page = Model.CurrentPage < Model.TotalPages ? Model.CurrentPage + 1 : Model.TotalPages }))">
            <img src="~/Content/img/btn_next.png" /></a>
        <a href="@Html.Raw(Url.Action("List", new { keyword = ViewData["Keyword"], cate = ViewData["CurrentCate"], page = Model.TotalPages }))">
            <img src="~/Content/img/btn_last.png" /></a>
            共 @Model.TotalPages 页
    </div>

    }
}
